package com.xbs.controller.hitchhiking;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xbs.controller.base.BaseServlet;
import com.xbs.controller.enterprise.DateJsonValueProcessor;
import com.xbs.entity.EmployeeEntity;
import com.xbs.service.hitchhiking.EmpAdminService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.util.CycleDetectionStrategy;
/**
 * 后台查询员工的ajax处理
 * @author dell
 */
@WebServlet("/backstage/selempajax")
public class SelEmpAjaxServlet extends BaseServlet{

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		EmpAdminService emp = new EmpAdminService();
		
		/**
		 * 根据员工的姓名，编号，身份证查询员工信息
		 */
	
		String str = req.getParameter("seltext");
		List<EmployeeEntity> emplst =  emp.getEmpByThree(str);
		JsonConfig jsonConfig = new JsonConfig();   
		jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);   
		jsonConfig.registerJsonBeanProcessor(java.sql.Date.class, new DateJsonValueProcessor());  
		jsonConfig.setExcludes(new String[]{"handler","hibernateLazyInitializer"});    
		JSONArray jsonArray = JSONArray.fromObject(emplst,jsonConfig);
		//JSONObject obj =JSONObject.fromObject(emplst,jsonConfig); 
		resp.getWriter().print(jsonArray);
		
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
}
